<template>
  <div class="content" v-if="jobList.length > 0">
    <span class="tinyTitle">
      <div class="titleFlag"></div>
      {{ "关联职位" }}
    </span>
    <template v-if="jobList.length > 20">
      <div
        class="contentItem"
        v-for="(item, index) in getShowJobList()"
        :key="index"
      >
        <el-tag type="success" v-if="index < 20" @click="handleContentClick(item)">{{
          item.positionName
        }}</el-tag>
        <el-button
          type="primary"
          size="small"
          @click="dialogJobVisible = true"
          v-else
          >更多<i class="el-icon-arrow-right el-icon--right"></i
        ></el-button>
      </div>
      <el-dialog
        title="关联职位"
        :visible.sync="dialogJobVisible"
        append-to-body
        center
      >
        <div class="dialogContent">
          <div
            class="dialogContentItem"
            v-for="(item, index) in jobList"
            :key="index"
          >
            <el-tag type="success" @click="handleContentClick(item)">{{ item.positionName }}</el-tag>
          </div>
        </div>
      </el-dialog>
    </template>
    <template v-else>
      <div class="contentItem" v-for="(item, index) in jobList" :key="index">
        <el-tag type="success" @click="handleContentClick(item)">{{ item.positionName }}</el-tag>
      </div>
    </template>
  </div>
</template>

<script>
import { getCampusTagPositions } from "@/api/home.js";

export default {
  name: "majorRelateJobList",
  props: {
    positionTagId: {
      type: String,
      default: "",
    },
  },
  watch: {
    positionTagId: {
      handler(val) {
        if (val) {
          this.getCampusTagPositionsFn();
        }
      },
      immediate: true,
    },
  },
  data() {
    return {
      jobList: [],
      dialogJobVisible: false,
    };
  },
  computed: {},
  mounted() {
    this.getCampusTagPositionsFn();
  },
  methods: {
    getShowJobList() {
      return this.jobList.slice(0, 21);
    },
    getCampusTagPositionsFn() {
      if (!this.positionTagId) {
        return;
      }
      getCampusTagPositions({ positionTagId: this.positionTagId }).then(
        (res) => {
          if (res.code === 200) {
            this.jobList = res.data;
            // console.log("getCampusTagPositions---------------------->", res);
          }
        }
      );
    },
    handleContentClick(item, index) {
      // console.log("handleContentClick---------->", item);
      let routeData = this.$router.resolve({
        path: "/position-detail",
        query: {
          // fatherTitle: `${item.topTitle} · ${item.parentTitle}`,
          id: item.ylPositionId || item.positionId,
          name: item.positionName,
          superToken: this.$route.query.superToken || "",
          SecretKey: this.$route.query.SecretKey || "",
          customerName: this.$route.query.customerName,
          // collect: true,
        },
      });
      window.open(routeData.href, "_blank");
    },
  },
};
</script>

<style lang="scss">
.content {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  margin: 0px 12px;
  .tinyTitle {
    display: flex;
    width: 100%;
    align-items: center;
    font-size: 18px;
    margin-top: 16px;
    color: #222;
    font-weight: bold;
    margin-bottom: 22px;
    .titleFlag {
      width: 5px;
      height: 15px;
      border-radius: 3px;
      background: #4880ff;
      margin-right: 12px;
    }
  }
  .contentItem {
    margin: 6px 12px 6px 0px;
    //显示鼠标手
    cursor: pointer;
  }
}
.dialogContent {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  .dialogContentItem {
    margin: 6px 12px 6px 0px;
    cursor: pointer;
  }
}
</style>
